package demo.practice.leetcode_eveyday;

public class P663 {

    public static void main(String[] args) {

        System.out.println((1 << 31) - 1);
        P663 p663 = new P663();
        p663.judgeSquareSum(2);
    }

    public boolean judgeSquareSum(int c) {
        //双指针？？
        int i = 0;
        int j = Math.min(c, 1 << 16);//2^31 - 1 integer的最大值


        while (i <= j) {
            if ((long) j * j + (long) i * i == (long) c)
                return true;

            if ((long) j * j + (long) i * i > (long) c) {
                //减小j
                long tmp = j >> 1;
                if (tmp * tmp + (long) i * i <= (long) c) {
                    j--;
                } else {
                    j = j >> 1;
                }
            } else {

                long tmp = i << 1;

                if ((long) j * j + tmp * tmp >= (long) c) {
                    i++;
                } else {
                    if (i == 0)
                        i++;
                    else
                        i = i << 1;
                }
            }

        }
        return false;
    }
}
